package com.zhongkai.controller;

import com.zhongkai.app.service.SupplierProductService;
import com.zhongkai.app.service.SupplierService;
import com.zhongkai.model.utils.TTHelp;
import com.zhongkai.model.utils.ZhongkaiResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 供应商
 */
@Controller
public class SupplierController {


    @Autowired
    private SupplierService supplierService;

    @Autowired
    private SupplierProductService supplierProductService;

    /**
     * 添加供应商
     *
     * @param sup_name    供应商名称
     * @param sup_address 地址
     * @param sup_attn    联系人
     * @param sup_phone   电话
     * @param sup_mail    邮箱
     * @param sup_remark  备注
     */

    @RequestMapping(value = "/supplier/add", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult supplier_add(String sup_name, String sup_address, String sup_attn, String sup_phone, String sup_mail, String sup_remark) {


        String uuid = TTHelp.generate();
        ZhongkaiResult result = supplierService.addSupplier(uuid, sup_name, sup_address, sup_attn, sup_phone, sup_mail, sup_remark);

        return result;
    }


    /**
     * 修改供应商
     *
     * @param id          供应商id
     * @param sup_name    供应商名称
     * @param sup_address 地址
     * @param sup_attn    联系人
     * @param sup_phone   电话
     * @param sup_mail    邮箱
     * @param sup_remark  备注
     */

    @RequestMapping(value = "/supplier/update", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult supplier_update(@RequestParam(defaultValue = "0") String id, String sup_name, String sup_address, String sup_attn, String sup_phone, String sup_mail, String sup_remark) {

        ZhongkaiResult result = supplierService.updateSupplier(id, sup_name, sup_address, sup_attn, sup_phone, sup_mail, sup_remark);

        return result;
    }


    /**
     * 删除供应商
     *
     * @param id 供应商id
     */

    @RequestMapping(value = "/supplier/remove", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult supplier_remove(@RequestParam(defaultValue = "0") Long id) {

        ZhongkaiResult result = supplierService.removeSupplier(id);

        return result;
    }


    /**
     * 分页获取供应商信息
     *
     * @param page 当前页数
     * @param rows 每页数据条数
     */

    @RequestMapping(value = "/supplier/list", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult supplier_list(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer rows) {

        ZhongkaiResult result = supplierService.listSupplier(page, rows);

        return result;
    }


    //-----------------------供应商产品-----------------------------


    /**
     * 添加产品
     *
     * @param supUuid  厂家uuid
     * @param supName  厂家名称
     * @param proName  产品名称
     * @param proPrice 产品单价
     * @param proUnit  产品单位
     */

    @RequestMapping(value = "/supplier/add_product", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult addProduct(String supUuid,
                                     String supName,
                                     String proName,
                                     String proPrice,
                                     String proUnit) {

        ZhongkaiResult result = supplierProductService.addProduct(supUuid, supName, proName, proPrice, proUnit);

        return result;
    }


    /**
     * 产品修改
     * @param proUuid  产品uuid
     * @param supUuid  厂家uuid
     * @param supName  厂家名称
     * @param proName  产品名称
     * @param proPrice 产品单价
     * @param proUnit  产品单位
     */

    @RequestMapping(value = "/supplier/update_product", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult updateProduct(String proUuid,
                                     String supUuid,
                                     String supName,
                                     String proName,
                                     String proPrice,
                                     String proUnit) {

        ZhongkaiResult result = supplierProductService.updateProduct(proUuid, supUuid, supName, proName, proPrice, proUnit);

        return result;
    }


    /**
     * 产品删除
     *
     * @param proUuid  产品uuid
     */

    @RequestMapping(value = "/supplier/remove_product", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult removeProduct(String proUuid) {

        ZhongkaiResult result = supplierProductService.removeProduct(proUuid);

        return result;
    }


    /**
     * 产品列表
     *
     * @param page  页码
     * @param rows  数据条数
     * @param sup_uuid 供应商UUID
     */
    @RequestMapping(value = "/supplier/list_product", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult listProduct(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer rows,String sup_uuid) {

        ZhongkaiResult result = supplierProductService.listProduct(page,rows,sup_uuid);

        return result;
    }
}
